/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pt.regcolm.servico;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import pt.regcolm.sqlcon.BDPathCon;

/**
 * REST Web Service
 *
 * @author Tiago
 */
@Path("showValues")
public class ShowValuesResource {

    private final static BDPathCon myCon = BDPathCon.getBDPathCon();
    
    @Context
    private UriInfo context;

    /**
     * Creates a new instance of ShowValuesResource
     */
    public ShowValuesResource() {
    }

    /**
     * Retrieves representation of an instance of pt.regcolm.entities.ShowValuesResource
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("application/json")
    public String getJson() {
        //SELECT * FROM medidas.medicao;
        try {
            String toSend = "";
            CallableStatement sStmt = myCon.getCon().prepareCall("SELECT * FROM medidas.medicao");
            ResultSet rs = sStmt.executeQuery();
            
            while(rs.next()){
                toSend += "ID: "+rs.getInt("idMedicao")+" Latitude: "+rs.getFloat("latitude")+
                        " Longitude: "+rs.getFloat("longitude")+
                        " Numero Abelhas: "+rs.getInt("nAbelhas")+
                        " Peso: "+rs.getDouble("peso")+
                        " TempInterior: "+rs.getDouble("tInterior")+
                        " TempExterior: "+rs.getDouble("tExterior")+
                        " HumInterior: "+rs.getDouble("hInterior")+
                        " TimeAdded: "+rs.getTimestamp("addedDate")+
                        "\n";
            }
            
            return toSend;
        } catch (SQLException ex) {
            Logger.getLogger(RegistoResource.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    /**
     * PUT method for updating or creating an instance of ShowValuesResource
     * @param content representation for the resource
     * @return an HTTP response with content of the updated or created resource.
     */
    @PUT
    @Consumes("application/json")
    public void putJson(String content) {
    }
}
